package deepbrain.simnetwork.mechanism;

import deepbrain.simnetwork.network.Network;
import deepbrain.simnetwork.network.NetworkState;
import deepbrain.simnetwork.network.NodeState;

public class NoisyMechanism extends GenericMechanism {

	private final GenericMechanism mechanism;
	private double temperature;

	public NoisyMechanism(GenericMechanism mechanism) {
		this.mechanism = mechanism;
	}

	public NoisyMechanism(GenericMechanism mechanism, double temperature) {
		this.mechanism = mechanism;
		this.temperature = temperature;
	}

	public NodeState nextNodeState(int node, Network network, NetworkState state) {
		NodeState oriState = mechanism.nextNodeState(node, network, state);
		double oriProb = oriState.getFiringProbability();
		double newProb = oriProb * (1 - temperature) + temperature / 2;
		return NodeState.newNodeState(newProb);
	}

}
